<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Common\Api\UserApi;
class OutOfStorageController extends BaseController {
    private $adminUser = null;
    public function _initialize(){
    	parent::_initialize();
    	$this->adminUser = new UserApi();

    }
	//获取后台管理员的信息
    public function index(){
      $inout = I('request.inout','','trim');
       $type = I('request.type','','trim');
      $this->assign('inout',$inout);
      $this->assign('type',$type);
      $this->display();
    }

   public function OutOfStorageList(){
         $inout =I('request.inout','','trim');
         $type =I('request.type','','trim');
         $where['inout'] = $inout;
         if($inout == 'in'){
            if($type == 3){
              $where['type'] =3;
            }else{
               $where['type'] = 1;
            }
         }
         if($inout == 'out'){
          $where['type'] = 6;
         }
        // print_r($where);exit;
          $title =I('request.title','','trim');
        if(!empty($title)){
           $where['sn'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }
        $start_time = I('request.start_time','','trim');
        $end_time = I('request.end_time','','trim');

        //如果两个为空，没有条件
        //否则 一个为空，一个有值，两个有值 
        if(!(empty($start_time) && empty($end_time))){ 
            $start_time = empty($start_time)?date("Y-m-d"):$start_time;
            $end_time = empty($end_time)?date("Y-m-d"):$end_time;
            if($start_time>$end_time){
                 $temp=$end_time;
                 $end_time=$start_time;
                 $start_time=$temp;
            }  

         $start_time = strtotime($start_time);
         $end_time = strtotime($end_time);
          $where['create_time'] = array(between,array($start_time,$end_time));
           // $str =" and create_time between '".time($start_time)."' and '".time($end_time)."'"; 
        } 
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = 'a.*,b.username';
       $_where_order_field['alias']="a";
        $_where_order_field["order"] = 'id desc';
        $_where_order_field["join"] =array('left join vip_user b on a.creatorid = b.id');
        $_datalist= $this->_getListsFromModel('stockinout',$_where_order_field);
        foreach ($_datalist['lists'] as $key => $value) {
          $list = D('stockinout_item')->where('stockinoutid= '.$value['id'])->order('createtime desc')->select();
          $value['list']=$list;
          $_datalist['lists'][$key] = $value;
        }
         // print_r($_datalist['lists']);exit;
        $this->assign('lists',$_datalist);
        $this->display();
   }


//出入库详情
public function OutOfStorageGoodsDetails(){
  $id = I('request.id','','trim');
  $inout = I('request.inout','','trim');
  $this->assign('id',$id);
  $this->assign('inout',$inout);
  $this->display('goods_details');

}


public function OutOfStorageGoodsDetailsList(){
  $id = I('request.id','','trim');
  $where['stockinoutid'] = $id;
   $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'id desc';
        $_datalist= $this->_getListsFromModel('stockinout_item',$_where_order_field);
       
        $this->assign('lists',$_datalist);
       $this->display('goods_details_list');
}




}
